﻿using System;
using UnityEngine;

namespace MrPP.SerriedCabinet
{
    public class Cell : MonoBehaviour
    {
        [SerializeField]
        private CellShelve _shelve;

        public CellShelve shelve
        {

            get { return _shelve; }
        }
        [SerializeField]
        private CellHightlight _hightlight;

        public CellHightlight hightlight {

            get { return _hightlight; }
        }
        [SerializeField]
        private CellCheck _check;


        public CellCheck check
        {

            get { return _check; }
        }
        public Location location;
        public Box.Type type {
            get {
                return location.location.type;
            }
            set {
                location.location.type = value;
            }


        }
        public int layer {
            get
            {
                return location.location.layer;
            }
            set
            {
                location.location.layer = value;
            }


        }

        public int box
        {
            get
            {
                return location.location.box;
            }
            set
            {
                location.location.box = value;
            }
        }
        public int sile
        {
            get
            {
                return location.location.sile;
            }
            set
            {
                location.location.sile = value;
            }
        }
        public void  Start() {
            CellManager.Instance.onState += doState;
        }

        private void doState(CellManager.Type type)
        {
            _check.gameObject.SetActive(false);
            _hightlight.gameObject.SetActive(false);
            _shelve.gameObject.SetActive(false);

            if (type == CellManager.Type.Check)
            {
                _check.gameObject.SetActive(true);
                _check.refresh();
            }
            else if (type == CellManager.Type.Hlight)
            {
                _hightlight.gameObject.SetActive(true);
            }
            else if (type == CellManager.Type.Shelve)
            {
                _shelve.gameObject.SetActive(true);
            }
        }

        void OnDestroy() {
            if (CellManager.IsInitialized) {
                CellManager.Instance.onState -= doState;
            }
        }
        public void setHlight(bool enable)
        {
            _hightlight.gameObject.SetActive(enable);
        }
        public void setShelve(bool enable) {
            _shelve.gameObject.SetActive(enable);
        }
        public void setCheck(bool enable)
        {
            _check.gameObject.SetActive(enable);
        }
       
    }
}